﻿using System;
using System.Collections.Generic;
using Contracts.Entities;
using Contracts.Library;
using Definition.Import;
using Client.Properties;

namespace Client.Processes
{
    public class ImportMovies
    {    
          
        private Asynchronizer<string> asynchronizer;
        private Synchronizer<IEnumerable<MovieItem>> synchronizer;
        private ImportMoviesService importMovieItems;

        public ImportMovies()
        {
            this.asynchronizer = new Asynchronizer<string>(false);
            this.synchronizer = new Synchronizer<IEnumerable<MovieItem>>();
            this.importMovieItems = new ImportMoviesService();

            asynchronizer.OnProcessing += m => importMovieItems.Process(m);
            importMovieItems.OnCompleted += m => synchronizer.Process(m);
            synchronizer.OnCompleted += m => OnCompleted(m);
        }

        public void Process()
        {         
            asynchronizer.Process(Settings.Default.movieRootPath);
        }

        public event Action<IEnumerable<MovieItem>> OnCompleted;
    }
}
